-
Notifications
You must be signed in to change notification settings - Fork 81
[CORE] Refactor XferCRC to make it branchless and to remove winsock dependency #1228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Perhaps we could go for even fewer branches by using the data size as a template parameter. Most of the call sites use a size that's known at compile-time. |
Replacing the winsock call is good. Removing the hibit branch also makes sense, because the branch predictor likely does not work well there (50% chance). I would like to see a performance comparison when this works without any remaining logical mismatch. |
Fixed the logic on validity handling of the leftover bytes. |
9949da4
to
aa01517
Compare
rebased with main, just going to make some other tweaks |
639521e
to
11539cd
Compare
Tested and tweaked with the switch replacing the second loop, it doesn't mismatch with the golden replays and you would expect it to mismatch pretty quckly if it was going to. |
Are you seeing any improvements in overall performance? |
I still need to look into performance testing, need to make a game replay under debug, might just do it with some AI since they can really hit different systems hard. |
val = htonl(val); | ||
addCRC (val); | ||
case 3: | ||
val += (c[2] << (2 * 8)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I overlooked that this would be invalid if data
is NULL
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add fallthrough to these cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if i do switch(leftover * validData)
that should then be caught in the default case.
11539cd
to
f3c4219
Compare
tweaked the switch to catch when data is null, so we don't have valid data. |
This PR refactors the XferCRC to make the code branchless and to remove the winsock dependency within it.
There may be minimal performance improvement from this as other factors will need changing in the data being passed to the CRC to further improve the performance.
The winsock dependency has been replaced with the endian compat library instead.